package com.itshizhan.demo1;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Java8 {
    public static void main(String[] args) {
        // 获取当前日期， yyyy-MM-dd
        LocalDate today = LocalDate.now();
//        System.out.println(today);
        // 获取当前时间，HH:mm:ss.SSSSSSSSS pattern.
        LocalTime now = LocalTime.now();
//        System.out.println(now);

        // 获取当前日期和时间
        LocalDateTime instance = LocalDateTime.now();
//        System.out.println(instance);

        //输入如下：
        //2022-06-05
        //21:13:35.031
        //2022-06-05T21:13:35.031

        // 获取带时区的时间
        // 获取中国的时区
        ZonedDateTime tzInstance = ZonedDateTime.now(ZoneId.of("GMT+08"));
        //CTT - Asia/Shanghai
        ZonedDateTime tzInstanceShanghai = ZonedDateTime.now(ZoneId.of("Etc/GMT-8"));
        ZonedDateTime utcInstanceShanghai = ZonedDateTime.now(ZoneId.of("UTC+8"));
//        System.out.println(tzInstance);
//        System.out.println(tzInstanceShanghai);
//        System.out.println(utcInstanceShanghai);

        //时间格式化
        LocalDateTime instanceNotFarmat = LocalDateTime.now();
        // java.time.format.DateTimeFormatter
        DateTimeFormatter formatter
                = DateTimeFormatter.ofPattern("dd-MM-yyyy hh:mm");

        String formattedString = formatter.format(instanceNotFarmat);
        // System.out.println(formattedString);

        Instant instant = Instant.now();
        System.out.println(instant);
        // 获取当前时区的时间（本地时间）
        ZonedDateTime zonedDateTime = Instant.now().atZone(ZoneId.systemDefault());
        System.out.println(zonedDateTime);

        Locale currentLocale = Locale.getDefault();
        System.out.println(currentLocale.getCountry());
        System.out.println(currentLocale.getLanguage());

    }
}
